#ifndef DATADEFINATION_H
#define DATADEFINATION_H

#include <QHash>
#include <QList>
#include <QString>


enum eNetworkStatus {
    networkConnected,
    networkUnconnected,
    networkTimeout,
    networkError,
    networkStatusEnd
};

const QString networkStatusDescription[networkStatusEnd] =
{
    QObject::tr("Network Connected!"),
    QObject::tr("Network Disconnected!"),
    QObject::tr("Network Timeout!"),
    QObject::tr("Network Error!")
};

enum eLoginStatus {
    loginSuccessful,
    loginFailed,
    renameSuccessful,
    renameFailed,
    logoutSuccessful,
    logoutFailed,
    loginStatusEnd
};

const QString loginStatusDescription[loginStatusEnd] =
{
    QObject::tr("Login Success!"),
    QObject::tr("Login Failed!"),
    QObject::tr("Rename Success!"),
    QObject::tr("Rename Failed!"),
    QObject::tr("Logout Success!"),
    QObject::tr("Logout Failed!")
};

class userInfo
{
public:
    inline void setName(const QString & name)  { mName = name; }
    inline void setIp(const QString & ip) { mIp =ip; }
    inline const QString & getName() const { return mName; }
    inline const QString & getIp() const { return mIp; }
    inline bool operator==(const userInfo & obj) const { return this->mIp == obj.mIp && this->mName == obj.mName; }
    inline userInfo & operator=(const userInfo & obj) { this->setIp(obj.getIp()); this->setName(obj.getName()); return *this; }

private:
    QString mName;
    QString mIp;
};

class recordInfo
{
public:
    inline void setErrorCode(int errorCode) { mErrorCode = errorCode; }
    inline void setContent(const QString & content) { mContent = content; }
    inline void setName(const QString & name) { mName = name; }
    inline const QString & getContent() const { return mContent; }
    inline const QString & getName() const { return mName; }
    inline const int getErrorCode() const { return mErrorCode; }
    inline recordInfo & operator=(const recordInfo & obj)
    { this->setErrorCode(obj.getErrorCode()); this->setContent(obj.getContent()); this->setName(obj.getName()); return *this; }

private:
    int mErrorCode;
    QString mName;
    QString mContent;
};

class recordListSet
{
public:
    ~recordListSet();

    inline bool hasRecordWith(const QString & ip) const { return mHash.contains(ip); }
    inline const QList<recordInfo> * getRecordList(const QString & ip) const { return mHash.value(ip); }
    bool clearRecordInfo(const QString & ip);
    bool insertRecordInfo(const QString & ip, const recordInfo & info);

private:
    void destroyListSet();

private:
    QHash<QString, QList<recordInfo>*> mHash;
    QList<QList<recordInfo>*> mListSet;
};

#endif // DATADEFINATION_H
